<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('用户配置')"/>
</head>
<body>
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">配置名称</label>
                    <input type="hidden" name="id" th:value="${config.configId}" name="configId" />
                    <div class="layui-input-block">
                        <input th:value="${config.configName}"  autocomplete="off" class="layui-input" lay-verify="required" lay-affix="clear" name="configName" placeholder="请输入配置名称" type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">配置KEY</label>
                    <div class="layui-input-block">
                        <input th:value="${config.configKey}" readonly class="layui-input" lay-verify="required"  name="configKey" placeholder="请输入配置KEY" type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">配置Value</label>
                    <div class="layui-input-block">
                        <input th:value="${config.configValue}" autocomplete="off" class="layui-input" name="configValue" lay-affix="clear" placeholder="请输入Value" type="text">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否内置</label>
                    <div class="layui-input-block">
                        <select name="configType" lay-filter="configType" >
                            <option value="">请选择</option>
                            <option value="Y" th:selected="${config.configType == 'Y'}" >是</option>
                            <option value="N" th:selected="${config.configType == 'N'}">否</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea placeholder="若有备注请输入" th:text="${config.remark}" class="layui-textarea" name="remark"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button class="pear-btn pear-btn-primary pear-btn-sm" lay-filter="user-save" lay-submit="" type="submit">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button class="pear-btn pear-btn-sm" type="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;

        form.verify({
            // 单选
            radioReq: function(value,item){
                let $ = layui.$;
                let verifyName=$(item).attr('name')
                    , verifyType=$(item).attr('type')
                    ,formElem=$(item).parents('.layui-form')//获取当前所在的form元素，如果存在的话
                    ,verifyElem=formElem.find('input[name='+verifyName+']')//获取需要校验的元素
                    ,isTrue= verifyElem.is(':checked')//是否命中校验
                    ,focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
                if(!isTrue || !value){
                    //定位焦点
                    focusElem.css(verifyType=='radio'?{"color":"#FF5722"}:{"border-color":"#FF5722"});
                    //对非输入框设置焦点
                    focusElem.first().attr("tabIndex","1").css("outline","0").blur(function() {
                        focusElem.css(verifyType=='radio'?{"color":""}:{"border-color":""});
                    }).focus();
                    return '必填项不能为空';
                }
            }
        });
        form.on('submit(user-save)', function (data) {
            $.ajax({
                url: '/system/config/update',
                data: data.field,
                dataType: 'json',
                // contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.message, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.message, {icon: 2, time: 3000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>